home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / shells / kiss-0.11 / kiss-0 / kiss / src / listdir.c < prev    next >
C/C++ Source or Header  |  1995-03-23  |  952b  |  55 lines

  1. #include "kiss.h"
  2.  
  3. static int listdirfiles (char *path, LsFlags fl)
  4. {
  5.     glob_t
  6.     globres;
  7.     register int
  8.     i;
  9.     
  10.     if (! glob (path, 0, NULL, &globres))
  11.     for (i = 0; i < globres.gl_pathc; i++)
  12.         if (listfile (globres.gl_pathv [i], fl))
  13.         {
  14.         globfree (&globres);
  15.         return (1);
  16.         }
  17.  
  18.     globfree (&globres);
  19.     return (0);
  20. }
  21.         
  22. int listdir (char *dir, LsFlags fl)
  23. {
  24.     struct stat
  25.     statbuf;
  26.     char
  27.     path [FILENAMELEN];
  28.     register int
  29.     ret = 0;
  30.     
  31.     if (stat (dir, &statbuf) || ! S_ISDIR (statbuf.st_mode))
  32.     return (warning ("\"%s\" is not an accessible directory", dir));
  33.  
  34.     if (strcmp (dir, "."))
  35.     {
  36.     if (fl.showall)
  37.     {
  38.         strcpy (path, dir);
  39.         strcat (path, "/.*");
  40.         ret += listdirfiles (path, fl);
  41.     }
  42.     strcpy (path, dir);
  43.     strcat (path, "/*");
  44.     ret += listdirfiles (path, fl);
  45.     }
  46.     else
  47.     {
  48.     if (fl.showall)
  49.         ret += listdirfiles (".*", fl);
  50.     ret += listdirfiles ("*", fl);
  51.     }
  52.  
  53.     return (ret);
  54. }
  55.